import axios from 'axios'

axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
// 创建axios实例
const service = axios.create({
  baseURL: '/api',
  timeout: 30000,
  // 禁用 Cookie 等信息
  // withCredentials: false,
})

// request拦截器
service.interceptors.request.use(
  (config) => {
    return config
  },
  (error) => {
    console.log(error)
    Promise.reject(error)
  }
)

// 响应拦截器
service.interceptors.response.use(
  async (res) => {
    return res.data
  },
  (error) => {
    console.log('err' + error)
    return Promise.reject(error)
  }
)

export default service
